import Vue from 'vue';
const ruleModal = Vue.extend(require('./ruleModal.vue').default);
let modalList ={};
let modal = {
  showModal(options) {
    if (typeof options != "object"&&options.el==undefined) return;
    let modalInstance = new ruleModal({ propsData:{"Filter": options.Filter,"Title": options.Title,"all": options.all,"id": options.id} });
    modalInstance.vm = modalInstance.$mount()
    modalInstance.vm.$on('onClose', (_index)=> {
      this.hideModal(_index)
    })
    modalInstance.vm.$on('onSave', (data)=> {
      if(options.saveDataFun!=undefined){
        options.saveDataFun(data);
      }
    })
    options.el.appendChild(modalInstance.vm.$el)
    Vue.nextTick(() => {
      modalInstance.modalVisible = true;
    });
    modalList[modalInstance._uid] = {"parent":options.el,"child":modalInstance}
    return modalInstance._uid
  },
  hideModal(_index) {
    setTimeout(() => {
      let obj = modalList[_index];
      obj.parent.removeChild(obj.child.vm.$el);
      obj.child.$destroy();
      modalList[_index] = null
      delete(modalList[_index])
    }, 200);
  },
  closeModal(_index) {
    let obj = modalList[_index];
    if(obj==undefined||obj==null) return;
    obj.child.modalVisible = false;
    this.hideModal(_index);
  }
}
export default modal; 